package edu.uci.ics.multicast.overlay;

import java.util.LinkedList;
import java.util.List;

public class OverlayNode extends MulticastNode {
	
	private String virtualIndex;
	private String ip;
	private List<Path> listPath = new LinkedList<Path>();

	private boolean visited = false;
	private boolean receivingMessage = false;
	
	public OverlayNode(String index, String virtualIndex, String ip) {
		super.setIndex(index);
		this.virtualIndex = virtualIndex;
		this.ip = ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getIp() {
		return ip;
	}

	public void setVirtualIndex(String virtualIndex) {
		this.virtualIndex = virtualIndex;
	}

	public String getVirtualIndex() {
		return virtualIndex;
	}
	
	public void addPath(Path path) {
		listPath.add(path);
	}

	public List<Path> getListPath() {
		return listPath;
	}

	@Override
	public String toString() {
		return "OverlayNode [index=" + super.getIndex() + ", virtualIndex=" + virtualIndex + ", ip=" + ip + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((ip == null) ? 0 : ip.hashCode());
		result = prime * result
				+ ((virtualIndex == null) ? 0 : virtualIndex.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		OverlayNode other = (OverlayNode) obj;
		if (ip == null) {
			if (other.ip != null)
				return false;
		} else if (!ip.equals(other.ip))
			return false;
		if (virtualIndex == null) {
			if (other.virtualIndex != null)
				return false;
		} else if (!virtualIndex.equals(other.virtualIndex))
			return false;
		return true;
	}

	public void setVisited(boolean visited) {
		this.visited = visited;
	}

	public boolean isVisited() {
		return visited;
	}

	public void setReceivingMessage(boolean receivingMessage) {
		this.receivingMessage = receivingMessage;
	}

	public boolean isReceivingMessage() {
		return receivingMessage;
	}

	
}
